//
//  HKUIKitViewController.m
//  HKiOSTools
//
//  Created by 胡锦涛 on 2020/12/22.
//

#import "HKUIKitViewController.h"
#import <objc/runtime.h>
#import "CommonBundle.h"
// 架构框架
#import "BifrostHeader.h"
#import "UIKitModuleService.h"
// 实例
#import "HKPrefixHeader.h"
#import "HKModelMap.h"
#import "HKModelUser.h"
#import "HKIrregularButtonController.h"
@interface HKUIKitViewController ()

@end

@implementation HKUIKitViewController
+ (void)load {
    [Bifrost bindURL:kRouteUIKitPage
           toHandler:^id _Nullable(NSDictionary * _Nullable parameters) {
        return [HKUIKitViewController new];
    }];
}
- (void)initDataSource {
    self.dataSource = [[QMUIOrderedDictionary alloc] initWithKeysAndObjects:
                       @"HKTheme", [CommonBundle imageNamed:@"icon_grid_button"],
                       @"HKConsole", [CommonBundle imageNamed:@"icon_grid_label"],
                       @"ViewController Orientation", [CommonBundle imageNamed:@"icon_grid_orientation"],
                       @"HKNavigationController", [CommonBundle imageNamed:@"icon_grid_navigation"],
                       @"YogerKit-移动端FlexBox", [CommonBundle imageNamed:@"icon_grid_cell"],
                       @"HKDatePicker", [CommonBundle imageNamed:@"icon_grid_textView"],
                       @"HKAddressPicker", [CommonBundle imageNamed:@"icon_grid_control"],
                       @"HKIrregularButton", [CommonBundle imageNamed:@"icon_grid_nsobject"],
                       nil];
    //
    //    @"QMUITextField", UIImageMake(@"icon_grid_textField"),
    //    @"QMUISlider", UIImageMake(@"icon_grid_slider"),
    //    @"QMUIAlertController", UIImageMake(@"icon_grid_alert"),
    //    @"QMUITableView", UIImageMake(@"icon_grid_cell"),
    //
    //    @"QMUINavigationController", UIImageMake(@"icon_grid_navigation"),
    //    @"UISearchBar+QMUI", UIImageMake(@"icon_grid_search"),
    //    @"UITabBarItem+QMUI", UIImageMake(@"icon_grid_tabBarItem"),
    //    @"UIColor+QMUI", UIImageMake(@"icon_grid_color"),
    //    @"UIImage+QMUI", UIImageMake(@"icon_grid_image"),
    //    @"UIImageView+QMUI", UIImageMake(@"icon_grid_imageView"),
    //    @"UIFont+QMUI", UIImageMake(@"icon_grid_font"),
    //    @"UIControl+QMUI", UIImageMake(@"icon_grid_control"),
    //    @"UIView+QMUI", UIImageMake(@"icon_grid_view"),
    //    @"NSObject+QMUI", UIImageMake(@"icon_grid_nsobject"),
    //    @"CAAnimation+QMUI", UIImageMake(@"icon_grid_caanimation"),
}

- (void)setupNavigationItems {
    [super setupNavigationItems];
    self.title = @"QMUIKit";
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem qmui_itemWithImage:UIImageMake(@"icon_nav_about") target:self action:@selector(handleAboutItemEvent)];
    AddAccessibilityLabel(self.navigationItem.rightBarButtonItem, @"打开关于界面");
}

- (void)didSelectCellWithTitle:(NSString *)title {
    UIViewController *viewController = nil;
    if ([title isEqualToString:@"HKTheme"]){
        viewController = [Bifrost handleURL:kRouteThemePage];
    }else if ([title isEqualToString:@"HKConsole"]){
        viewController = [Bifrost handleURL:kRouteConsolePage];
    }else if ([title isEqualToString:@"HKNavigationController"]) {
        viewController = [Bifrost handleURL:kRouteNavigationListPage];
    }else if ([title isEqualToString:@"ViewController Orientation"]){
        viewController = [Bifrost handleURL:kRouteOrientationPage];
    }else if ([title isEqualToString:@"YogerKit-移动端FlexBox"]){
        viewController = [Bifrost handleURL:kRouteFlexBoxPage];
    }else if ([title isEqualToString:@"HKDatePicker"]){
        viewController = [Bifrost handleURL:kRouteDatePickerPage];
    }else if ([title isEqualToString:@"HKAddressPicker"]){
        viewController = [Bifrost handleURL:kRouteAddressPickerPage];
    }else if ([title isEqualToString:@"HKIrregularButton"]){
        viewController = [HKIrregularButtonController new];
    }
    if (viewController != nil) {
        viewController.title = title;
        [self.navigationController pushViewController:viewController animated:YES];
    }else {
        [self hk_showMessage:@"暂未开发，敬请期待~"];
    }
}

- (void)handleAboutItemEvent {
    QMUIThemeManagerCenter.defaultThemeManager.currentThemeIdentifier = HKThemeIdentifierGrapefruit;
}

@end
